package fr.mma.achievement.controller;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import fr.mma.achievement.model.AchievementType;
import fr.mma.achievement.model.dto.AchievementDTO;
import fr.mma.achievement.model.persistence.Achievement;

public class Factory {
	
	private static Map<AchievementType, String> nameFromType = new HashMap<AchievementType, String>();
	
	static {
		nameFromType.put(AchievementType.CADET, "Cadet");
		nameFromType.put(AchievementType.COMMANDANT, "Commandant");
		nameFromType.put(AchievementType.LIEUTENANT, "Lieutenant");
	}
	
	private Factory() {
	};

	public static AchievementDTO build(final Achievement achievementMetier) {
		final AchievementDTO achievement = new AchievementDTO();
		achievement.setType(achievementMetier.getType());
		achievement.setFinish(achievementMetier.isFinish());
		achievement.setName(nameFromType.get(achievementMetier.getType()));
		return achievement;
	}

	public static Collection<AchievementDTO> buildAchievement(final List<Achievement> achievementsMetier) {
		final Collection<AchievementDTO> achievements = new ArrayList<AchievementDTO>();
		if (achievementsMetier != null) {
			for (Achievement achievementMetier : achievementsMetier) {
				achievements.add(build(achievementMetier));
			}
		}
		return achievements;
	}
}

